<template>
	<div class="app-container">
		<jk-operation-card ref="box1" class="margin-bottom-10">
			<div class="flex-between-center-wrap">
				<div class="flex-start-center-wrap">
				</div>
				<div class="flex-end-center-wrap">
					<jk-select v-model="searchParams.workshopId" clearable placeholder="区域" :option-list="workshopList" size="small" class="search-bar-item-size1 margin-5-0 item-gap"></jk-select>
					<jk-select v-model="searchParams.processCode" clearable placeholder="工序" value-key-name="code" :option-list="processList" size="small" class="search-bar-item-size1 margin-5-0 item-gap"></jk-select>
					<jk-select v-model="searchParams.typeId" clearable placeholder="停机类型" :option-list="stopTypeList" size="small" class="search-bar-item-size2 margin-5-0 item-gap"></jk-select>
					<jk-select v-model="searchParams.shutdownState" clearable placeholder="停机状态" :option-list="stopStateList" size="small" class="search-bar-item-size2 margin-5-0 item-gap"></jk-select>
					<jk-search-input v-model="searchParams.machineNameOrCode" placeholder="机台编号或名称" size="small" class="search-bar-item-size2 margin-5-0 item-gap" clearable @on-search="onSearchBtn" />
					<jk-search-button @click="onSearchBtn"></jk-search-button>
				</div>
			</div>
		</jk-operation-card>

		<jk-card>
			<jk-table ref="jkTable" border :loading="tableLoading" :data="tableData" :height="tableHeight + 20">
				<vxe-column
					v-for="(item, index) in tableColumnList"
					:key="index"
					:title="item.title"
					:align="item.align"
					:field="item.keyName"
					:sortable="item.sortable"
					:fixed="item.fixed ? item.fixed : ''"
					:min-width="item.minWidth"
					:width="item.width"
				>
					<template slot-scope="scope">
						<jk-state-bar v-if="item.keyName === 'shutdownState'" :show-icon="false" :state-list="stopStateList" :state="scope.row.shutdownState"></jk-state-bar>
						<jk-state-bar v-else-if="item.keyName === 'typeId'" :state-list="stopTypeList" :state="scope.row.typeId"></jk-state-bar>
						<span v-else>{{ scope.row[item.keyName] }}</span>
					</template>
				</vxe-column>
			</jk-table>

			<!-- 分页组件 -->
			<footer ref="box2" class="flex-end-center margin-top-10">
				<jk-page
					:page-index="searchParams.pageNo"
					:page-sizes="searchParams.pageSizes"
					:page-size="searchParams.pageSize"
					:total="totalCount"
					@on-change="onPageChange"
				/>
			</footer>
		</jk-card>
	</div>
</template>

<script>
    import calHeight from '/src/mixins/cal-table-height';
    import { pageConfig } from '/src/utils/jk/jk-tool';
    import getMenuColumn from '../../../mixins/getMenuColumn';
    import handlerCache from '../../../mixins/handler-cache';
    import { productionMachineShutdownRecordsMachinePage } from '../../../api/production/reports';
    import { stopStateList, stopTypeList } from '../../../utils/jk/status-option-list';

    export default {
        name: 'ShutdownReport',
        components: {
        },
        mixins: [calHeight, getMenuColumn, handlerCache],
        data() {
            return {
                apiItem: {
                    'page': productionMachineShutdownRecordsMachinePage
                },
                stopStateList: stopStateList,
                stopTypeList: stopTypeList,
                processList: [],
                workshopList: [],
                tableLoading: true,
                tableData: [],
                totalCount: 0,
                searchParams: {
                    pageNo: pageConfig.pageNo,
                    pageSize: pageConfig.pageSize,
                    typeId: null,
                    shutdownState: null,
                    processCode: '',
                    workshopId: null,
                    machineNameOrCode: ''
                }
            };
        },
        mounted() {
            this.getDependentData();
        },
        methods: {
            onPageChange(e, size) {
                this.$set(this.searchParams, 'pageNo', e);
                this.$set(this.searchParams, 'pageSize', size);
                this.getListRequest();
            },
            clearCacheMethod() {
                // Object.assign(this.$data, this.$options.data());
                this.$nextTick(() => {
                    this.getDependentData();
                });
            },
            async getDependentData() {
                this.$set(this.searchParams, 'processCode', this.$store.state.user.userProcess.defaultProcessCode);
                this.processList = this.$store.state.user.userProcess.processList ? this.$store.state.user.userProcess.processList.filter(x => !['QH', 'TB', 'EB', 'MB'].includes(x.code.toUpperCase())) : [];
                this.$set(this.searchParams, 'workshopId', this.$store.state.user.userWorkshop.defaultWorkshopId);
                this.workshopList = this.$store.state.user.userWorkshop.workshopList;

                this.tableLoading = true;
                await this.getMenuColumnListRequest();
                await this.getListRequest();
                this.tableLoading = false;
            },
            /** 查询列表 */
            getListRequest() {
                this.tableLoading = true;
                return this.apiItem['page'](this.searchParams).then(res => {
                    this.tableLoading = false;
                    if (res.data.status === 200) {
                        this.tableData = res.data.res;
                        this.totalCount = res.data.count;
                    }
                });
            },
            /** 搜索按钮操作 */
            onSearchBtn() {
                this.searchParams.pageNo = 1;
                this.totalCount = 1;
                this.getListRequest();
            }
        }
    };
</script>
<style>
</style>
